//
//  BuyCommonTicketRequest.m
//  EasyToo
//
//  Created by zhengzhe on 13-8-25.
//
//

#import "BuyCommonTicketRequest.h"

@implementation BuyCommonTicketRequest

- (id)buyCommonTickets:(id<ServerCommunicationDelegate>)delegate
            cinemaName:(NSString*)cinemaName
              cinemaId:(NSString*)cinemaId
                 count:(NSString*)count
             userPhone:(NSString*)userPhone
                 price:(NSString*)price
                   tid:(NSString*)tid
{
    self = [super init];
    if (self) {
        self.delegate = delegate;
        self.requestName = @"BuyCommonTicketRequest";
        [self.headerJsonDict setObject:@"018013" forKey:@"TranCode"];
        
        self.url = PROTOCOL_ORDER_URL;
        
        [self.bodyJsonDict setObject:tid forKey:@"tid"];
        [self.bodyJsonDict setObject:[self URLEncodedString:cinemaName] forKey:@"cinemaName"];
        [self.bodyJsonDict setObject:cinemaId forKey:@"cinemaId"];
        [self.bodyJsonDict setObject:@"90" forKey:@"tEnableDay"];
        [self.bodyJsonDict setObject:count forKey:@"count"];
        [self.bodyJsonDict setObject:userPhone forKey:@"userPhone"];
        [self.bodyJsonDict setObject:price forKey:@"price"];
        
        //银联支付价格
        [self.headerJsonDict setObject:price forKey:@"TxAmt"];

        [self buildJsonRequest];
    }
    return self;
}


- (NSString*)URLEncodedString:(NSString*)input
{
    NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                                           (CFStringRef)input,
                                                                           NULL,
                                                                           CFSTR("!*'();:@&=+$,/?%#[]"),
                                                                           kCFStringEncodingUTF8);
    [result autorelease];
    return result;
}


@end
